/* ************************************************************************************************

	Copyright (c) 2005-2006, IGR
	All Rights Reserved.
	Licensed under the Apache License version 2.0 or above.
	For more information on licensing, see:
        http://www.apache.org/licenses/


 ************************************************************************************************
 Objet GRID
 VERSION:0.85
 DATE:15/06/2006
 ************************************************************************************************
Init parameter in objPar (object of parameter):
name		Name of the HTML element
left		Left position (in pixel)
top			Top position (in pixel)
height		Height (in pixel or %)
parent		Reference of an HTML or a javascript element parent of the grid html element
TabEntete	Array that contains the Header title of the grid
tabTypeCol	Array of array containing for each header the data type (string,date,number) and the header width
bNavig		Display in navigation mode (true) or in block mode (false)
rang		Number of displayed lines in navigation mode(other than the header)
cellActive	Indicate if reactivity is on the cell(true) or on the line (false)
sortable	True if columns are sortable
multiSelect	True if you can select as many lines as you want
lineHeight	height of a line
boolPrint	Content can be printed(true/false)
switchable	can switch from block mode to navigation mode and vice versa(true/false)
actifClic	Enable click (true/false)
autoResizableW	Width is the same as parent width(true/false)
writable	true if the cells are writable

   

/* ID FOR:
        -header cells:this.id+"_CellEntete_"+column number
        -grid line:this.id+"_LineTab_"+line number
        -grid cells:this.id+"_CellTab_"+line number+"_"+cell number

The grid object has a property called "tabData" which contains all the data and there properties. this array will be helpfull to manipulate the grid. For example the onclick method pass the line and cell index. The value can be retrieve using this array (tabData[indLine][indCell]) Its an array where each line is an array that contains:
the values of the differents cells
a sel attribute (true if the line is selected)
a cellProp object that represents for each cells
a sel attribute (true if the cell is selected).
a object which properties represents style properties to set.

For a grid of n row, the n first element of the array contain the value of the cell.
You can use additional row to store some data associated to a cell (id, database link...).

The writable attribute allow (when it is set to true) to put the cell in a writable state (with input field) after a double click.
The type of the input depend of the type of the cell define in the tabTypeCol of the constructor. You can also use a combo by
adding in the third column a collection of text/value like:
["string",60,[[140,140],[160,160],[180,180]]]
You can validate the new value by using the enter key or click on another cell or line
You can reset your typing by pressing the ESC key.

On Mozilla (that doesn't work yet on IE)
you can use the tabulation key to switch on next cell (or SHIFT+TAB for the previous cell)
You can use up and down arrow to switch to the same cell of the previous or next line
*/

// *************************************
// CONSTRUCTOR
// *************************************

 /**   
   * @constructor
   * @param {String} name		Name of the HTML element
   * @param {int} left		 	Left position (in pixel)
   * @param {int} top			Top position (in pixel)
   * @param {String} height		Height (in pixel or %)
   * @param {String} parent		Reference of an HTML or a javascript element parent of the grid html element
   * @param {Array} TabEntete	Array that contains the Header title of the grid
   * @param {Array} tabTypeCol	Array of array containing for each header the data type (string,date,number) and the header width
   * @param {boolean} bNavig	Display in navigation mode (true) or in block mode (false)
   * @param {int} rang			Number of displayed lines in navigation mode(other than the header)
   * @param {boolean} cellActive	Indicate if reactivity is on the cell(true) or on the line (false)
   * @param {boolean} sortable	True if columns are sortable
   * @param {boolean} multiSelect	True if you can select as many lines as you want
   * @param {int} lineHeight	height of a line
   * @param {boolean} boolPrint	Content can be printed(true/false)
   * @param {boolean} switchable	can switch from block mode to navigation mode and vice versa(true/false)
   * @param {boolean} actifClic	Enable click (true/false)
   * @param {boolean} autoResizableW	Width is the same as parent width(true/false)
   * @param {boolean} writable	true if the cells are writable
   */
rialto.widget.Grid=function(objPar){    
    //base constructor
/**
	* Keeps message to show.
	* @private
	* @type String
*/
    this.base = rialto.widget.AbstractComponent;
    objPar.type="grid";
    this.base(objPar);
    this.base=null;
    //Default value
	this.WIDTHSEP = 3;
    this.navigation=false;
    this.tabData=new Array();
    this.tabEntete=objPar.TabEntete;
    this.NbreCol=objPar.TabEntete.length;   
    this.NbreLig=0;
    this.rang=15;  
    
    this.autoResizeContenu = false;
    this.autoResizeParent = false;
    this.cellActive=false;    
    this.sortable=true;
    this.multiSelect=false;
    this.lineHeight=16;
    this.decalage=0;
    this.boolPrint = true;
    this.switchable = true;
    this.actifClic=true;    
    this.titrePrint = "TABLEAU DE RESULTAT";    
    this.writable=false;
    this.widthLastCell=20;
    this.indLineClic=-1;
    
    //set the value with the properties of the objPar object
    if (rialto.lang.isBoolean(objPar.bNavig)){
        this.navigation = objPar.bNavig;        
    }
    if (rialto.lang.isBoolean(objPar.cellActive)){
        this.cellActive = objPar.cellActive;        
    }
    if (rialto.lang.isBoolean(objPar.sortable)){
        this.sortable= objPar.sortable;        
    }
	if (rialto.lang.isBoolean(objPar.multiSelect)){
        this.multiSelect= objPar.multiSelect;        
    }
    if (rialto.lang.isNumber(objPar.lineHeight)){
        this.lineHeight = objPar.lineHeight;            
    }       
    if (rialto.lang.isNumber(objPar.rang)){
        this.rang = objPar.rang;            
    }
    if (rialto.lang.isNumber(objPar.widthLastCell)){
        this.widthLastCell = objPar.widthLastCell;            
    }
    if (rialto.lang.isBoolean(objPar.actifClic)){
        this.actifClic = objPar.actifClic;        
    }
    if (rialto.lang.isBoolean(objPar.boolPrint)){
        this.boolPrint = objPar.boolPrint;        
    }
    if (rialto.lang.isBoolean(objPar.switchable)){
        this.switchable = objPar.switchable;
    }   
    if (rialto.lang.isString(objPar.printTitle)){
        this.printTitle = objPar.printTitle;        
    }    
    if (rialto.lang.isBoolean(objPar.autoResizeContenu)){
        this.autoResizeContenu = objPar.autoResizeContenu;        
    }
    if (rialto.lang.isBoolean(objPar.autoResizeParent)){        
        this.autoResizeParent = objPar.autoResizeParent;        
        this.autoResizableH=this.autoResizeParent;
    }                                
    if (rialto.lang.isBoolean(objPar.writable)){
        this.writable = objPar.writable;
        this.lineHeight=Math.max(20,parseInt(this.lineHeight));        
    }  

    
	//Array for header (width,and dat type)
	this.tabTypeCol=new Array();
	if (objPar.tabTypeCol){
    	this.tabTypeCol=objPar.tabTypeCol;
   	}
	else {
		for(var i=0;i<this.NbreCol;i++){
	    	this.tabTypeCol.push(["string",100]);
	    }
	}
    //width of the grid according to each cell width
    
    this.width=((this.NbreCol-1)*parseInt(this.WIDTHSEP))+40+this.widthLastCell;  //petit calcul pour rajouter les tailles des cellules d?cor?es    
    for(var i=0;i<this.NbreCol;i++){
    	this.width+= this.tabTypeCol[i][1];       
    }    
    //keep init width
    this.widthMin=this.width;
    /*
    //tableau des variations ? appliquer ? la largeur initiale de chaque colonne pour obtenir la largeur courante
    this.tVarDimCol = new Array();
    for(var i=0;i<this.NbreCol;i++){
      this.tVarDimCol[i] = 0;
    }           
    */  
     
    var line,cell;     
    var oThis=this;
    
    // *******************************************
	// GENERATION OF DOM ELEMENTS
	// *******************************************
	
    //External div    
    this.divExt.id=this.id+"_divExt";    
    this.divExt.style.top= this.top;
    this.divExt.style.left= this.left;    
    this.divExt.style.width= this.width+"px";
    this.divExt.style.position=this.position;

    //this.divExt.style.border= "1px solid red";
                    
    //===========Navigation area=========  
    if(this.switchable || this.navigation){
	    this.Div_nav= document.createElement("DIV");
	    this.Div_nav.id=this.id+"_Div_nav";
	    this.Div_nav.className="Div_nav";
	    this.Div_nav.style.height="24px";
	    this.Div_nav.style.display='none';
	    this.divExt.appendChild(this.Div_nav);        
	    //left image
	    this.arrG = new rialto.widget.Image("leftEdgeRoundDashBoard",0,1,this.Div_nav,"","",{position:'absolute'});    
	    //right image
	    this.arrD = new rialto.widget.Image("rightEdgeRoundDashBoard",255,1,this.Div_nav,"","",{position:'absolute'});
	    
	    //center with navigation button and text
	    this.Div_navBoutTexte= document.createElement("DIV");
	    this.Div_navBoutTexte.id=this.id+"_Div_nav";
	    this.Div_navBoutTexte.style.position="absolute";
	    this.Div_navBoutTexte.style.left="22px";
	    this.Div_navBoutTexte.style.width="243px";
	    this.Div_navBoutTexte.style.height="24px";
	    this.Div_navBoutTexte.style.backgroundColor="#DFECF3";
	    this.Div_nav.appendChild(this.Div_navBoutTexte);
	    
	    
	    
	    //create button and hide them
	    Parent = this.Div_navBoutTexte;
	    //first button
	    this.bouFirst = new rialto.widget.Image("btonFirstDoctOff",0,5,Parent,this.rang+" premiers","btonFirstDoctOn",{position:'absolute'});
	    this.bouFirst.onclick=function () {oThis.firstN();};
	    this.bouFirst.setVisible(false);
	    //previous button
	    this.boutPrevious = new rialto.widget.Image("leftArrowOff",20,5,Parent,this.rang+" pr?c?dents","leftArrowOn",{position:'absolute'});
	    this.boutPrevious.onclick=function () {oThis.previousN();};
	    this.boutPrevious.setVisible(false);
	    //text
	    this.Div_text=document.createElement("DIV");
	    this.Div_text.className="Div_text";
	    this.Div_text.id=this.id+"_Div_text";    
	    this.Div_navBoutTexte.appendChild(this.Div_text);
	    //next button
	    this.boutNext = new rialto.widget.Image("rightArrowOff",190,5,Parent,this.rang+" prochains","rightArrowOn",{position:'absolute'});
	    this.boutNext.onclick=function () {oThis.nextN();};
	    this.boutNext.setVisible(false);
	    //last button 
	    this.boutLast = new rialto.widget.Image("btonLastDoctOff",210,5,Parent,this.rang+" derniers","btonLastDoctOn",{position:'absolute'});
	    this.boutLast.onclick=function () {oThis.lastN();};
	    this.boutLast.setVisible(false);
	    if (this.navigation){this.Div_nav.style.display='block';}       
    }
    //===========header html array =========  
    this.tableauEntete=document.createElement("DIV");     
    this.tableauEntete.id=this.id+"tableEntete";    
    this.tableauEntete.style.width='100%'; 
    this.tableauEntete.style.height=this.lineHeight+'px';
    this.tableauEntete.position="relative";  
    this.divExt.appendChild(this.tableauEntete);             
    
    //===========data html array =========  
    this.tableauHTML=document.createElement("DIV");    
    this.divExt.appendChild(this.tableauHTML);
    this.tableauHTML.style.width= '100%';                    
    this.tableauHTML.style.fontSize="0";
    this.tableauHTML.style.overflow='auto';
    this.tableauHTML.id=this.id+"tableData";     
    this.tableauHTML.position="relative";
    //arrow to sort coluumn
    this.arrowUp = document.createElement("IMG");
    this.arrowUp.src = rialtoConfig.pathRialtoE + "images/imgTableau/upsimple.png";
    this.arrowUp.className = "arrow";    
    this.arrowDown = document.createElement("IMG");
    this.arrowDown.src = rialtoConfig.pathRialtoE + "images/imgTableau/downsimple.png";
    this.arrowDown.className = "arrow";

    //image for selected line or cell
    this.divCoche=document.createElement("DIV");
    this.divCoche.className = "coche";
    coche = document.createElement("IMG");
    coche.src = rialtoConfig.pathRialtoE + "images/imgTableau/coche.gif";
    this.divCoche.appendChild(coche);    
    //seperate cell
    this.cellSep=document.createElement("DIV");    
    this.cellSep.className='cellSep';        
    this.cellSep.style.width=this.WIDTHSEP;
    this.cellSep.style.height=this.lineHeight+'px';        
    this.cellSep.style.backgroundImage="url('"+ rialtoConfig.pathRialtoE +"images/imgTableau/fillet.gif')";
    
         
	//===========create element in header array =========   
    line=document.createElement("DIV");     
    line.style.height=this.lineHeight+'px';         
    line.style.width=this.width-20+'px';   
            
    //1rst cell with image
    cell=document.createElement("DIV");
    cell.style.width="8px";
    cell.style.height=this.lineHeight+'px';
    cell.className="cellEntete";    
    cell.type="cell";       
    img=document.createElement("IMG");
    img.src=rialtoConfig.pathRialtoE + "images/imgTableau/bordbleu_g.gif";                
    img.style.position="relative";
    img.style.height="100%";
    img.style.width="100%";    
    cell.appendChild(img);
    line.appendChild(cell);
    for(var j=0;j<this.NbreCol;j++)
    {
        /*******creation of the header column*********/
        cell=document.createElement("DIV");                                            
        cell.id=this.id+"_CellEntete_"+j;
        cell.className="cellEntete";
        cell.style.backgroundColor= "#DFECF3";
        cell.style.width = this.tabTypeCol[j][1]+"px";
        
        cell.ind=j;
                
        var div=document.createElement("DIV"); 
        div.className="DivTexEntete";
        div.title=this.tabEntete[j];
        div.innerHTML=this.tabEntete[j];
        cell.appendChild(div);        
        //add the cell to the line
        line.appendChild(cell)                    
        //if the grid is sortable add the add the click evant on the cell
        if(this.sortable){
            cell.onclick=function(){                                
                oThis.triColonne(this.ind);                                
                oThis.refreshGrid();                
            }
        }
        //separation between 2 cell           
        cellSep=this.cellSep.cloneNode(true);                    
        line.appendChild(cellSep);
        
        //Drag and drop behavior to resize the column
        cellSep.oCiu = this;      
/*
        cellSep.dd= DragAndDrop;  // - pour l instant td est choisi uniquement pour definir synchro sur le bon objet
                                  // sinon il faut un parametre oSynchro pour le sp?cifier
                                  // - il faudrait restreindre le deplact ds la def du DD pour l instant la rstriction
                                  // se fait sur le redimensionnement ? l oeuvre dans synchro (avec max (0...))
*/
        this.oCiu = this;
        this.heightVisibleCol = function () {       
            var temp= Math.min(   parseInt(this.oCiu.getRealHeight())
                             ,      parseInt(this.oCiu.divExt.offsetHeight)
                               -    (this.oCiu.navigation ? parseInt(this.oCiu.Div_nav.style.height)
                                                           :0));            
            return temp;
        }
/*
        cellSep.dd(   
                    {        objetCibleEvt      : cellSep
                            ,objetADeplacer     : cellSep
                            ,fantome            : {  aspect: 'aPlat'
                                                    ,top :  "window.event?this.oCiu.navigation ? parseInt(this.oCiu.Div_nav.style.height):0:0"
                                                    ,height:'this.oCiu.heightVisibleCol()'
                                                  } 
                            ,orientation        : 'h'
                            ,majDyn             : true  // maj dyn des limites si les dimensions du tableau peuvent changer
                            ,bRectLim           : true
                            ,rectLim            : { 
                                                    // left : 0  limite ? gche = limite tableau
                                                    left:  'parseInt(this.previousSibling.firstChild.offsetLeft)'
                                                          +' + 12 + parseInt(this.previousSibling.offsetLeft)'  
// le respect de la distance avec le s?parateur de gche en cas de deplact vers la gche
// est n?cessaire : sinon l'evenement mouse move ne parient pas au s?parateur le texe chevauchant le sep !!
        // pour limiter le deplact vers la gche
                                                    ,right:'parseInt(this.parentNode.offsetWidth)-20'}   

//                            ,actionMup          : true
                    }
                ); 
*/

   rialto.widgetBehavior.affect(cellSep	
    							  ,'DragAndDrop'
    							  ,{
									ghost					: {
 								    				 aspect :'rect'
	      				    	    				 ,asChild: true
                                                    ,top    : 0//"window.event?this.oCiu.navigation ? parseInt(this.oCiu.Div_nav.style.height):0:0"
                                                    ,height : 'this.oCiu.heightVisibleCol()'
 								    }
 								    ,bSelectMark 			: false
    							    ,isWithLimitsDisplayed  : false    							    
                          			,movingLimits 			: {
                  										orientation: 'h'
                  										,rectLim  :{
                  											left:  'parseInt(this.previousSibling.firstChild.offsetLeft)'
                                                  					+ ' + 12 + parseInt(this.previousSibling.offsetLeft)' 
                                                            ,right:'parseInt(this.parentNode.offsetWidth)-20'}
                                                  					}
                  									  }
									
    							  );

        cellSep.synchroDDMup =  function(mod,posI){             
            // cell before the separation
            var c = this.previousSibling;              
            c.style.width= Math.max(10,parseInt(c.style.width) + mod.left);                        
            //apply the width change to the rest of the grid                
            oThis.reDimColTabData(c.ind,mod.left);            
        }    
    }
  	//last cell always empty
    this.DerCell=document.createElement("DIV");                                            
    this.DerCell.id=this.id+"_Cell"+j;
    this.DerCell.className="cellEntete";
    this.DerCell.style.backgroundColor= "#DFECF3";
    this.DerCell.style.width =this.widthLastCell;
    
    line.appendChild(this.DerCell);        
    //image
    cell=document.createElement("DIV");
    cell.className="cellEntete";
    cell.style.width="8px";
    cell.style.height=this.lineHeight+'px';        
    img=document.createElement("IMG");
    img.src=rialtoConfig.pathRialtoE + "images/imgTableau/bordbleu_d.gif";                
    img.style.position="absolute";
    img.style.height="100%";
    img.style.width="100%";
    cell.appendChild(img);                
    line.appendChild(cell);        
    //add this line to the header array
    this.tableauEntete.appendChild(line);

    //if the grid can switch
    if(this.switchable){        
        //hide the last cell with right corner
        var ind=this.tableauEntete.childNodes[0].childNodes.length-1;
        this.tableauEntete.childNodes[0].childNodes[ind].style.display='none';
        //increase width of the last empty data cell
        this.DerCell.style.width=parseInt(this.DerCell.style.width)+8;
        //add an image inside
        this.imgBascule=new rialto.widget.Image(rialtoConfig.pathRialtoE+"images/imgTableau/bt_bascul_off.gif",8,0,this.DerCell,"Changer le type d'affichage",rialtoConfig.pathRialtoE+"images/imgTableau/bt_bascul_on.gif",{position:'absolute'});
        this.imgBascule.onclick=function(){                               
            oThis.switchDisplayMode();
        }
    }
        
    if (objPar.parent) {this.placeIn(objPar.parent);};

    //contextual menu
    this.menuContex=new objMenuCont("men1",220);
    this.menuContex.createMenu(this.divExt);        
    this.menuContex.add("Select",false,false,false,rialtoConfig.pathRialtoE + "images/Entoure.gif");
    this.menuContex.addSeparation();
    this.menuContex.add("Switch display mode",this.switchable,false,false,rialtoConfig.pathRialtoE + "images/imgTableau/bt_bascul_off.gif");    
    if(this.boolPrint){this.menuContex.add("Print",true,false,false,rialtoConfig.pathRialtoE + "images/imTreeview/icone_compte_rendu.gif");}
    
    this.divExt.oncontextmenu =  function(e){
        oThis.menuContex.srcEvent=null;        
        oThis.menuContex.inactiveItem(0);
        oThis.menuContex.afficheMenu(e);        
    }
            
    this.menuContex.itemClickApplicatif=function(ind){
        //ind:index of selected item    

        //select the line
        if (ind==0){
            //si l'origine est une line ou une cellule
            if (oThis.menuContex.srcEvent!=null){
                oThis.menuContex.srcEvent.onclick();
            }
            return true;
        }
       
        
        //switch display mode
        if (ind==1){            
            oThis.switchDisplayMode();
            return true;
        } 
        
        //print
        if (ind==2){            
            oThis.print();
            return true;
        }  
    }    
        
    //release object
	objPar=null;
}


rialto.widget.Grid.prototype = new rialto.widget.AbstractComponent;


rialto.widget.Grid.prototype.onmouseover=function (){}
rialto.widget.Grid.prototype.onmouseout=function (){}




//PRINT FUNCTION
rialto.widget.Grid.prototype.print =function(){//PrintBehavior;
    //open the print window
    var widthGlobal=document.body.clientWidth;
    var heightGlobal=document.body.clientHeight;
    this.fenImp=window.open(rialtoConfig.pathRialtoE+'printTab.html','IMPRESSION',"height="+heightGlobal+",width="+widthGlobal+",top=0,left=0,scrollbars,resizable,toolbar,menubar");       
    //function to dend data
    this.rempFenImp();
}


rialto.widget.Grid.prototype.rempFenImp =function(){//PrintBehavior;
    //if the print window is open 
    if(this.fenImp.rempPage){
        //object with printable data
	    var obj=this.getInfoPrint();
        this.fenImp.rempPage(obj);
    }
    //else timeout until window is open
    else{        
        window.setTimeout("rialto.session.objects[\""+this.id+"\"].rempFenImp()",50);
    }
}


//object with following print information
//-header seperate by $
//-global title
//-nbcol (column number)
//-NbreLig (line number)
//-tabData (array of data)
rialto.widget.Grid.prototype.getInfoPrint =function(){
    var obj=new Object;    
    //contitution de la chaine des entetes et des tailles
    obj.strEntete=new String;
    obj.strEntete=this.tabEntete.join("$");    
    obj.tabEntete=this.tabEntete;    
    obj.strEntete=rialto.string.formatHTTP(obj.strEntete);   
    obj.titre=this.titrePrint;
    obj.NBCOL=this.tabEntete.length;
    obj.NbreLig=this.NbreLig;
    obj.tabData=this.tabData;
    return obj;
}

// ***********************************************************
// UPDATE ELEMENTS AFTER DOM INSERTION
// ***********************************************************


rialto.widget.Grid.prototype.adaptToContext = function(){
    
    var oThis=this;
    //INITIAL HEIGHT AND WIDTH
	if (this.autoResizableH){	   
	    this.divExt.style.height=this.getNewParentHeight()-this.divExt.offsetTop;
	}
	else{
	    this.divExt.style.height=this.height;
	}
	if (this.autoResizableW){
	    this.divExt.style.width=this.getNewParentWidth()-this.divExt.offsetLeft;
	}
	else{
	    this.divExt.style.width= this.width;
	}        
            
    //data array heigth
    this.tableauHTML.style.height=Math.max(0,this.divExt.offsetHeight-this.tableauHTML.offsetTop)+'px';
    //rank
    this.rang=Math.floor((parseInt(this.height)-24)/this.lineHeight)-1;    
    
    if (this.autoResizeContenu && !this.autoResizeParent){           
        this.resizeContenu();
    }    
    //si auto Width
    if(this.autoResizableW){
        this.updateWidth();
    }
    
    //if navigation mode center the area
    if (this.navigation){        
        ria.utils.measures.$centerW(this.Div_nav);
    }
            
}

// ***********************************************************
// RESIZE FUNCTIONS
// ***********************************************************

//resize column after drag & drop
rialto.widget.Grid.prototype.reDimColTabData = function(indCol,modDim) {
//============================================================              
       
        this.divExt.style.overflow='hidden';
        
	//save new width		
	this.width=parseInt(this.width)+modDim;              		
	//change divExt width
        this.divExt.style.width= this.width+"px";  
        //increase line width               
        this.tableauEntete.childNodes[0].style.width=parseInt(this.tableauEntete.childNodes[0].style.width) + modDim;         
        this.tabTypeCol[indCol][1]+=modDim;                
        
        
        //change each cell
        for (var i=0;i<this.tableauHTML.childNodes.length; i++){
            var line=this.tableauHTML.childNodes[i];
            //si il y a un sur texte on le redimensionne
            if(line.sTexte){            
                line.sTexte.style.width=this.width-20;
            }
            //get the cell
            cell=document.getElementById(this.id+"_CellTab_"+i+"_"+indCol);                    
            cell.style.width=parseInt(cell.style.width) + modDim;           
        }
        
        //if auto Width
        if(this.autoResizableW){                                                
            this.updateWidth();            
        }
        
        //if navigation mode center the area
        if (this.navigation){        
            ria.utils.measures.$centerW(this.Div_nav);
        }        
    	this.divExt.style.overflow='';
    	
    	
		//firefox bugg
		if(!rialtoConfig.userAgentIsIE && !this.navigation){
			this.setVisible(false);
			this.setVisible(true);		
		}
};

//TO UPDATE HEIGHT AND WITH ACCORDING TO THE PARENT
rialto.widget.Grid.prototype.updateSize= function(delta){            
	this.divExt.style.overflow='hidden';
    if (this.autoResizableH || this.autoResizeContenu){            
        this.updateHeight();        
    }
     //si auto Width
    if(this.autoResizableW){        
        this.updateWidth();
    }    
  	this.divExt.style.overflow='auto';
}

rialto.widget.Grid.prototype.updateWidth=function(){ 
if (this.autoResizableW){
        //get new width of the parent
	    var tailleCalc=parseInt(this.getNewParentWidth())-2;
	    //Set new size
	    //this.divExt.style.width=tailleCalc-this.divExt.offsetLeft;
	    //this.tableauEntete.childNodes[0].style.width=tailleCalc-20;
	    //get variation
    	var delta=tailleCalc-this.width-this.left;       
			    
	
    	var deltaReel=0;
    
	    //on calcule la difference par rapport ? la largeur actuelle            
	    var delta=tailleCalc-this.width-this.left;       
	    //on est plus petit que la place disponible et on depasse la taille min
	    if(delta>0 &&  (this.width+delta)>this.widthMin){ 
	        var deltaReel=delta;
	    }
	    else{
	        //on est plus gd que la place disponible
	        if(delta<0){
	            //on diminue la der col du max que l'on peut
	            //on regarde le delta max
	            var deltaMax=parseInt(this.DerCell.style.width)-20;
	            var deltaReel=-(Math.min(-delta,deltaMax));            
	        }    
	    }
	    //si une modif a ?t? calclul?e on l'applique
	    if(deltaReel!=0){
	        this.width+=deltaReel;
	        //on augmente la divGen et la line d'entete
	        this.divExt.style.width=this.width;
	        this.tableauEntete.childNodes[0].style.width=this.width-20;
	        //on memorise la taille de la derniere colonne       
	        this.widthLastCell+=deltaReel;
	        //on affecte la nouvelle taille de la derniere cellule            
	        this.DerCell.style.width=this.widthLastCell; 
	        //set new left to the image
	        if(this.imgBascule){
	        	this.imgBascule.setLeft(this.widthLastCell-20);
	        }     
	        //on rataille le tableau
	        for (var i=0;i<this.tableauHTML.childNodes.length; i++){
	            var line=this.tableauHTML.childNodes[i];
	            //si il y a un sur texte on le redimensionne
	            if(line.sTexte){            
	                line.sTexte.style.width=this.width-28;
	            } 
	            //on recupere la derniere cellule
	            ind=this.tableauHTML.childNodes[i].childNodes.length-2;
	            derCol=this.tableauHTML.childNodes[i].childNodes[ind];
	            derCol.style.width=this.widthLastCell;
	        }
	        //if navigation mode center the area
	        if (this.navigation){        
	            ria.utils.measures.$centerW(this.Div_nav);
	        }        
	    }
	}
}
/*
rialto.widget.Grid.prototype.updateWidth=function(){  	
      if (this.autoResizableW){
        //get new width of the parent
	    var tailleCalc=parseInt(this.getNewParentWidth());
	    this.divExt.style.width=tailleCalc-this.divExt.offsetLeft;
	    this.tableauHTML.style.width=tailleCalc-this.divExt.offsetLeft-this.tableauHTML.offsetLeft;		    
	    
	    //on calcule la difference par rapport ? la largeur actuelle            
	    
	    
    //get new width of the parent
    var widthPere=parseInt(this.getNewParentWidth());
    var delta=widthPere-this.width-this.left;       
    
    /*
    //on est plus petit que la place disponible et on depasse la taille min
    if(delta>0 &&  (this.width+delta)>this.widthMin){ 
        var deltaReel=delta;
    }
    else{
        //on est plus gd que la place disponible
        if(delta<0){
            //on diminue la der col du max que l'on peut
            //on regarde le delta max
            var deltaMax=parseInt(this.DerCell.style.width)-20;
            var deltaReel=-(Math.min(-delta,deltaMax));            
        }    
    }
    
	//look at the more we can decrease
    if(delta<0){
        //on diminue la der col du max que l'on peut
        //on regarde le delta max
        var deltaMin=parseInt(this.width-this.widthMin);
        var delta=-(Math.min(-delta,deltaMin));            
    }
        
    //apply the change
    if(delta!=0){
        this.width+=delta;
        //increase divExt,header line 
        this.divExt.style.width=this.width;
        this.tableauEntete.childNodes[0].style.width=this.width-20;
        //save new width of the last cell
        this.widthLastCell+=delta;
        //set new with to the last cell
        this.DerCell.style.width=this.widthLastCell; 
        //set new left to the image
        if(this.imgBascule){
        	this.imgBascule.setLeft(this.widthLastCell-20);
        }    
        //change each line of the data table
        for (var i=0;i<this.tableauHTML.childNodes.length; i++){
            var line=this.tableauHTML.childNodes[i];
            //si il y a un sur texte on le redimensionne
            if(line.sTexte){            
                line.sTexte.style.width=this.width-28;
            } 
            //change on last cell
            ind=this.tableauHTML.childNodes[i].childNodes.length-2;
            derCol=this.tableauHTML.childNodes[i].childNodes[ind];
            derCol.style.width=this.widthLastCell;
        }
        //if navigation mode center the area
        if (this.navigation){        
            ria.utils.measures.$centerW(this.Div_nav);
        }        
    }
	    
	}

}*/

rialto.widget.Grid.prototype.updateHeight=function(){        
    if (this.autoResizableH){
        //get new height of the parent
	    var tailleCalc=parseInt(this.getNewParentHeight());
	    this.divExt.style.height=tailleCalc-this.divExt.offsetTop;
	    this.tableauHTML.style.height=tailleCalc-this.divExt.offsetTop-this.tableauHTML.offsetTop;	    	
	    
	    //if navigation mode get new rank
		if (this.navigation){		    
		    this.rang=Math.floor(parseInt(this.tableauHTML.style.height)/this.lineHeight);                
		    //if there is data kneed to change the number of line according to the new rank
		    if(this.tabData.length>0){
		        //Start to 0
		        this.debInd=0;
		        //to rank or end
		        this.finInd=Math.min(this.debInd+this.rang,this.NbreLig);                     
		        this.refreshGrid();                
		    }
		}
		else{
		    //rank is size -navigation area size- 1 for the first line)    
		    this.rang=Math.floor((parseInt(this.divExt.style.height)-24)/this.lineHeight)-1;    
		}
	}    
}
/*rialto.widget.Grid.prototype.updateWidth = function() {
    traceExec("maj updateWidth Grid " +delta,1);
    //sauvegarde de l'overflow du parent
    over=this.parent.style.overflow;                   
    if (over==''){over='auto';}  
    this.parent.style.overflow='hidden';
    var deltaReel=0;
    
    //on calcule la difference par rapport ? la largeur actuelle            
    //on calcule la largeur du pere    
    var widthPere=this.parent.offsetWidth;    
    var delta=widthPere-this.width-this.left;       
    //on est plus petit que la place disponible et on depasse la taille min
    if(delta>0 &&  (this.width+delta)>this.widthMin){ 
        var deltaReel=delta;
    }
    else{
        //on est plus gd que la place disponible
        if(delta<0){
            //on diminue la der col du max que l'on peut
            //on regarde le delta max
            var deltaMax=parseInt(this.DerCell.style.width)-20;
            var deltaReel=-(Math.min(-delta,deltaMax));            
        }    
    }
    //si une modif a ?t? calclul?e on l'applique
    if(deltaReel!=0){
        this.width+=deltaReel;
        //on augmente la divGen et la line d'entete
        this.divExt.style.width=this.width;
        this.tableauEntete.childNodes[0].style.width=this.width-20;
        //on memorise la taille de la derniere colonne       
        this.widthLastCell+=deltaReel;
        //on calcul la nouvel taille de la derniere cellule            
        this.DerCell.style.width=this.widthLastCell; 
        //on repositionne l'image si elle existe
        if(this.imgBascule){this.imgBascule.style.left=parseInt(this.imgBascule.style.left)+deltaReel;}    
        //on rataille le tableau
        for (var i=0;i<this.tableauHTML.childNodes.length; i++){
            var line=this.tableauHTML.childNodes[i];
            //si il y a un sur texte on le redimensionne
            if(line.sTexte){            
                line.sTexte.style.width=this.width-28;
            } 
            //on recupere la derniere cellule
            ind=this.tableauHTML.childNodes[i].childNodes.length-2;
            derCol=this.tableauHTML.childNodes[i].childNodes[ind];
            derCol.style.width=this.widthLastCell;
        }
        //SI NAVIGATION ON CENTRE LA ZONE
        if (this.navigation){        
            ria.utils.measures.$centerW(this.Div_nav);
        }        
    }
    //remet l'overflow
    this.parent.style.overflow=over;
}
*/



//FOnction qui adape la taille au contenu si celui ci est inferieur ? la taille initiale
rialto.widget.Grid.prototype.resizeContenu=function(){       
    if (this.autoResizeContenu && !this.autoResizeParent){        
        //si jamais on a affich? moins de line que la place disponible on diminue le tableau 
        //taille reelle occup?e nbreline*tailleline
        tailleR=this.getRealHeight();          
        //on attribus cette taille si elle est inf?rieure ? la taille d?clar?e du cadre
        if(tailleR<parseInt(this.height)){      
            tailleNavig=0;
            if (this.navigation){
                tailleNavig=this.Div_nav.offsetHeight;
            }                        
            this.divExt.style.height=tailleR+tailleNavig;                  
            this.tableauHTML.style.height=tailleR+'px';                        
        }        
        else{
            //on redonne les tailles initiales
            this.divExt.style.height=this.height;
            //calcul de la taille du tableau de donn?es 
            this.tableauHTML.style.height=Math.max(0,this.divExt.offsetHeight-this.tableauHTML.offsetTop)+'px';             
        }
        //on propage au pere
        this.resizePereFrere();        
    }  
}

//return the real height of the grid according to the number of line
rialto.widget.Grid.prototype.getRealHeight = function () {
traceExec('this.lineHeight= '+this.lineHeight
		+' *this.NbreLig)= '+ this.NbreLig
		  + ' this.tableauEntete.offsetHeight= '+this.tableauEntete.offsetHeight,14);
	return (this.lineHeight*this.NbreLig)+this.tableauEntete.offsetHeight;
}

// ***********************************************************
// FUNCTIONS TO CHANGE  GRID CONTENT AND APPARENCE
// ***********************************************************

rialto.widget.Grid.prototype.switchDisplayMode = function(){
    //switch to block mode or navigation mode
    if(this.switchable){        
	    if (this.navigation){
	        this.navigation=false;
	        this.Div_nav.style.display='none';            
	        this.tableauHTML.style.height=parseInt(this.tableauHTML.style.height)+parseInt(this.Div_nav.style.height);
	    }
	    else{
	        this.navigation=true;        
	        this.tableauHTML.style.height=parseInt(this.tableauHTML.style.height)-parseInt(this.Div_nav.style.height);
	        this.Div_nav.style.display='block';            
	        //if navigation mode center the area
	        ria.utils.measures.$centerW(this.Div_nav);        
	    }                                    
        this.resizeContenu();        
        //if data are visible kneed to make change
        if (this.tabData.length>0){    
            //get new end index according to the mode
            this.debInd=0;
            if (!this.navigation){            
                this.finInd= this.NbreLig;                
            }
            else{               
                this.finInd=Math.min(this.rang,this.NbreLig);
            }            
            //refresh
            this.refreshGrid();             
        }
    }
}

rialto.widget.Grid.prototype.setText = function (text) {
//=============================
	this.Div_text.innerHTML=text;
}

//fonction qui efface les lines d'un tableau "HTML"
rialto.widget.Grid.prototype.effacelines = function (titre,forSubmit){ 
	rialto.deprecated('Grid','effacelines','deleteLines');
	this.deleteLines(titre,forSubmit);
}


rialto.widget.Grid.prototype.deleteLines = function(titre,forSubmit){

    this.indLigneClic=-1;

	//proper release
    var dataLines = this.tableauHTML.childNodes;
    for (var lnIdx=0;lnIdx<dataLines.length;lnIdx++){
        var dataLine = dataLines[lnIdx];
        if (dataLine.img){
            dataLine.img.onclick=null;
            dataLine.img=null;
        }
        dataLine.onmouseout=null;
        dataLine.onmouseover=null;
        for (var colIdx=0;colIdx<dataLine.childNodes.length;colIdx++){
            var dataItem = dataLine.childNodes[colIdx];
            dataItem.onclick=null;
            dataItem.oncontextmenu=null;
            dataItem.ondblclick=null;
            dataItem.onmouseout=null;
            dataItem.onmouseover=null;
        }
    }

    this.tableauHTML.innerHTML="";
    if (this.navigation){
        //update texte       
        this.setText(titre);
		//hide buttons
        this.bouFirst.setVisible(false);
        this.boutPrevious.setVisible(false);
        this.boutNext.setVisible(false);
        this.boutLast.setVisible(false);
    }    
}

//intialise the data by deleting line and javascript data
rialto.widget.Grid.prototype.initTab=function(){
    this.deleteLines();    
    this.tabData=new Array; 
}


//return the first line number with a col which contain valCol
//-1 if not found
rialto.widget.Grid.prototype.findLine=function(col,valCol){
    
    var ret=-1;
    var trouve=false;
    var i=0;
    var val;
    
    while(i<this.NbreLig && !trouve){
        val=this.tabData[i][col];
        if(val==valCol){
            ret=i;
            trouve=true;
        }
        else{i++;}        
    }
    
    return ret
        
}


//to delete the 'ind' line 
rialto.widget.Grid.prototype.deleteOneLine=function(ind){        
    //remove from javascript array    
    this.tabData.splice(ind,1);
    //refresh the grid
    this.fillGrid(this.tabData);
}


//Fill the grid with the data of the javascript array 
//TabData:javascript array 
//ind:index pf the column to sort
//boolOrder:sort order
rialto.widget.Grid.prototype.fillGrid=function(TabData,ind,boolOrder){
        
        this.NbreLig=TabData.length;
        //if more then 100 line switch to navigation mode (more faster to display)
        if(this.NbreLig>=100 && this.switchable && !this.navigation){
            this.switchDisplayMode();
        }        
        //save the data
        this.tabData=new Array();        
        this.tabData = (this.tabData.concat(TabData));
                
        //reset everything
        this.deleteLines();                 
        this.indLineClic=-1;
        //intialise the line with defalt value
        for(var i=0;i<this.NbreLig;i++){            
           this.initLine(i);                 
        }
        //set start and end index
        this.debInd=0;
        if (!this.navigation){            
            this.finInd= this.NbreLig;                
        }
        else{               
            this.finInd=Math.min(this.rang,this.NbreLig);
        }         
        //display the grid
        if(this.sortable){               
            if(!ind)ind=0;
            this.triColonne(ind,boolOrder);                
        }        
		this.refreshGrid();
        this.updateSize();
}

//this function initialize line with giving index 
rialto.widget.Grid.prototype.initLine=function(ind){	
    //selected state
    this.tabData[ind].sel=false;
    //associated texte
    this.tabData[ind].sTexte=null;         
    
    /*propertie array for each cell
        - selected state       
        - image reference in the cell
        - style object of the cell
    */
    var cellProp=new Array;
    for(var j=0;j<this.NbreCol+1;j++){
        cellProp[j]={sel:false,objPar:null,obStyle:null};                
    }
    this.tabData[ind].cellProp=cellProp; 

}

//display line between start and end index (not incluing)
rialto.widget.Grid.prototype.refreshGrid=function(){
    
    if (this.navigation){  
        //refresh navigation area
        this.majZoneNavigation();                    
    }     
    var tabINNERHTML=new Array();    
            
    //BOUCLES POUR LES LIGNES HTML A CREER
    for(var i=this.debInd;i<this.finInd;i++)
    {             
      tabINNERHTML.push(this.addLineWithINNER(i));                  
    }   
    //add the constituate inner
    this.tableauHTML.innerHTML=tabINNERHTML.join('');

    //set style and event function on each line and cell
    this.updateLineCell();    
}


rialto.widget.Grid.prototype.updateLineCell=function(){
//update line and cell for propertie and function

    var oThis=this;     
	//check all the line in the HTML data grid
	for (var i=0;i<this.tableauHTML.childNodes.length;i++){						
		line=this.tableauHTML.childNodes[i];
		//index of the line							
		tab=line.id.split("_");
		indL=tab[tab.length-1];		
		//save type,index and selected state on the line
		line.type="line";
        line.sel=false;
        line.ind=indL;	        
        //if the line was seleted 
	    if (this.tabData[indL].sel){this.selNode(indL,0);}
	    //if not cellActive attach function of mouse out and over
	    if (!this.cellActive){            
	    	line.onmouseout=function(){oThis.afterMouseout(this);};
	        line.onmouseover=function(){oThis.afterMouseover(this);};            
	    }	    	    
		for (var j=1;j<line.childNodes.length;j+=2){		
			if(line.childNodes[j].id.indexOf(this.id+"_CellTab_")!=-1){
				//for each cell
				cell=line.childNodes[j];
				//index of the cell
				tab=cell.id.split("_");
				indL=tab[tab.length-2];				
				indC=tab[tab.length-1];	
				//save type,cell index,line index  and selected state on the cell
				cell.ind=indC;
	            cell.indL=indL;
	            cell.type="cell";
	            cell.sel=false;
	            //if the cell had an image inside
	            //alert("L:"+indL+" C:"+indC);
	            if (this.tabData[indL].cellProp[indC].objPar!=null){                
	                this.addObjectInCell(indL,indC,this.tabData[indL].cellProp[indC].objPar);
	            }
	            //if the cell was selected
	            if (this.tabData[indL].cellProp[indC].sel){this.selNode(indL,indC);}
	            //apply the style
	            if (this.tabData[indL].cellProp[indC].obStyle!=null){	                
	                var obStyle=this.tabData[indL].cellProp[indC].obStyle;
	                this.setStyle(indL,indC,obStyle);       
	            }		
	            //click,contextmenu and dble click event
	            if (this.actifClic){
	                cell.onclick=function(){                    
	                    var tab=this.id.split("_");
	                    indC=tab[tab.length-1];
	                    indL=tab[tab.length-2];                    
	                    oThis.afterOnClick(indL,indC,true);
	                };
	                cell.oncontextmenu=function(e){
	                    var e=e?e:window.event;
	                    oThis.oncontextmenu(this,e);
	                };
	                
	                cell.ondblclick=function(){                    
	                    var tab=this.id.split("_");
	                    indC=tab[tab.length-1];
	                    indL=tab[tab.length-2];                    
	                    oThis.afterOnDbleClick(indL,indC,true);
	                };	                
	            }                        
	            //if cellActive attach function of mouse out and over
	            if (this.cellActive){            
	                cell.onmouseout=function(){oThis.afterMouseout(this);};
	                cell.onmouseover=function(){oThis.afterMouseover(this);};
	            }      	        
			}
		}	
	}	    
}



//fonction qui ajoute une ligne au niveau de l'objet (par innerHTML)
rialto.widget.Grid.prototype.addOneLine=function(tabLine){
	
	var oThis=this;
	
    this.NbreLig+=1;                
    //ajout au tableau JS
    if(!this.tabData){
        this.tabData=new Array;        
    }
    i=this.tabData.push(tabLine)-1;
    
    //on initialise la lignes   
    this.initLine(i);     
    /* 
    var tabINNERHTML=new Array();
    //constitution d innerHTML de la ligne
    tabINNERHTML.push(this.addLineWithINNER(i));      
    //ajout du inner au tabmeau HTML
    this.tableauHTML.innerHTML+=tabINNERHTML.join(''); 
    */
    //on va cr?er la lihne par javascript (pbme avec inner sur les lignes d?j? cr?es)
     //id de la ligne
    var idL=this.id+"_LineTab_"+i;    
    //CONSTITUTION DE LA LIGNE
    var divLigne=document.createElement("DIV");        
    divLigne.id=idL;
    divLigne.type="line";
    divLigne.sel=false;
    divLigne.ind=idL;	   	
    divLigne.className="grid_line";
    divLigne.style.height=this.lineHeight+"px";
    //1ere cellule
    var divCellDec=document.createElement("DIV");
    divCellDec.className="cellDec";
    divLigne.appendChild(divCellDec);
    if (!this.cellActive){            
    	divLigne.onmouseout=function(){oThis.afterMouseout(this);};
        divLigne.onmouseover=function(){oThis.afterMouseover(this);};            
    }	
    //CELLULES AVEC UN FOND BLANC ET IMAGES ARRONDIES
    if (i%2==1){         
        var img=document.createElement("IMG");
        img.className="imgCell";
        img.src=rialtoConfig.pathRialtoE + "images/imgTableau/bordblanc_g.gif"
        divCellDec.appendChild(img);
        
        for(var j=0;j<this.NbreCol;j++)            
        {           
            //id de la cellule
            idC=this.id+"_CellTab_"+i+"_"+j;            
            //cr?ation de la cellule
            var divCell=document.createElement("DIV");        
            divCell.id=idC;
            divCell.className="cellData";
            divCell.style.background="#FBFBFB";
            divCell.style.width=this.tabTypeCol[j][1]+"px";            
            divCell.ind=idC;
            divCell.indL=idL;
            divCell.type="cell";
            divCell.sel=false;
            if (this.cellActive){            
	        	divCell.onmouseout=function(){oThis.afterMouseout(this);};
	            divCell.onmouseover=function(){oThis.afterMouseover(this);};
	        } 
            //click,contextmenu and dble click event
            if (this.actifClic){
                divCell.onclick=function(){                    
                    var tab=this.id.split("_");
                    indC=tab[tab.length-1];
                    indL=tab[tab.length-2];                    
                    oThis.afterOnClick(indL,indC,true);
                };
                divCell.oncontextmenu=function(e){
                    var e=e?e:window.event;
                    oThis.oncontextmenu(this,e);
                };
                
                divCell.ondblclick=function(){                    
                    var tab=this.id.split("_");
                    indC=tab[tab.length-1];
                    indL=tab[tab.length-2];                    
                    oThis.afterOnDbleClick(indL,indC,true);
                };	                
            } 
            //cr?ation du texte de la cellule
            var divText=document.createElement("DIV");        
            divText.id=idC;
            divText.className="DivTexData";            
            divText.title=this.tabData[i][j];            
            divText.innerHTML=this.tabData[i][j];
            divCell.appendChild(divText);
            divLigne.appendChild(divCell);
            //cr?ation de la cellule de s?paration
            var divCellSep=document.createElement("DIV");
            divCellSep.className="cellSep";
            divLigne.appendChild(divCellSep);                       
        }
        //derniere cellule vide
        idC=this.id+"_CellTab_"+i+"_"+this.NbreCol;           
        //cr?ation de la cellule
        var divCell=document.createElement("DIV");        
        divCell.id=idC;
        divCell.className="cellData";
        divCell.style.background="#FBFBFB";
        divCell.style.width=this.widthLastCell+"px";                            
        divLigne.appendChild(divCell);
        //derniere cellule avec image
        divCellDec=document.createElement("DIV");
        divCellDec.className="cellDec";        
        var img=document.createElement("IMG");
        img.className="imgCell";
        img.src=rialtoConfig.pathRialtoE + "images/imgTableau/bordblanc_d.gif"
        divCellDec.appendChild(img);
        divLigne.appendChild(divCellDec);
    }
    //CELLULES SANS FOND BLANC ET SANS IMAGES ARRONDIES
    else{    
        for(var j=0;j<this.NbreCol;j++)            
        {           
            //id de la cellule
            idC=this.id+"_CellTab_"+i+"_"+j;            
            //cr?ation de la cellule
            var divCell=document.createElement("DIV");        
            divCell.id=idC;
            divCell.className="cellData";                
            divCell.style.width=this.tabTypeCol[j][1]+"px";
            divCell.ind=idC;
            divCell.indL=idL;
            divCell.type="cell";
            divCell.sel=false;
            if (this.cellActive){            
	        	divCell.onmouseout=function(){oThis.afterMouseout(this);};
	            divCell.onmouseover=function(){oThis.afterMouseover(this);};
	        } 
            //click,contextmenu and dble click event
            if (this.actifClic){
                divCell.onclick=function(){                    
                    var tab=this.id.split("_");
                    indC=tab[tab.length-1];
                    indL=tab[tab.length-2];                    
                    oThis.afterOnClick(indL,indC,true);
                };
                divCell.oncontextmenu=function(e){
                    var e=e?e:window.event;
                    oThis.oncontextmenu(this,e);
                };
                
                divCell.ondblclick=function(){                    
                    var tab=this.id.split("_");
                    indC=tab[tab.length-1];
                    indL=tab[tab.length-2];                    
                    oThis.afterOnDbleClick(indL,indC,true);
                };	                
            }             
            //cr?ation du texte de la cellule
            var divText=document.createElement("DIV");        
            divText.id=idC;
            divText.className="DivTexData";            
            divText.title=this.tabData[i][j];            
            divText.innerHTML=this.tabData[i][j];
            divCell.appendChild(divText);
            divLigne.appendChild(divCell);
            //cr?ation de la cellule de s?paration
            var divCellSep=document.createElement("DIV");
            divCellSep.className="cellSep";
            divLigne.appendChild(divCellSep);                       
        }
        //derniere cellule vide
        idC=this.id+"_CellTab_"+i+"_"+this.NbreCol;           
        //cr?ation de la cellule
        var divCell=document.createElement("DIV");        
        divCell.id=idC;
        divCell.className="cellData";            
        divCell.style.width=this.widthLastCell+"px";                    
        divLigne.appendChild(divCell);
        //derniere cellule avec image
        divCellDec=document.createElement("DIV");
        divCellDec.className="cellDec";
        divLigne.appendChild(divCellDec);
            
    }                   
    this.tableauHTML.appendChild(divLigne);
    
    //maj de la ligen et de ces cellules
    //this.updateLineCell();
    //retourne l'indice de la ligne cr?e    

    return i;
}


//return the HTML string corresponding to the line i
rialto.widget.Grid.prototype.addLineWithINNER=function(i){
    //line id
    var idL=this.id+"_LineTab_"+i;    
    //tempory array
    var tabTemp=new Array();    
    
    //construction of the line
    tabTemp.push('<DIV ID="'+idL+'" style="height:'+this.lineHeight+'px;" class="grid_line">');
    tabTemp.push('<DIV type="cell" class="cellDec">');        
    if (i%2==1){ 
        //cell with white background and image
        tabTemp.push('<IMG  class="imgCell" src="'+rialtoConfig.pathRialtoE + 'images/imgTableau/bordblanc_g.gif"></IMG>');
        tabTemp.push('</DIV>');
        for(var j=0;j<this.NbreCol;j++)            
        {           
            //cell id
            idC=this.id+"_CellTab_"+i+"_"+j;                       
            tabTemp.push('<DIV ID="'+idC+'" style="background:#FBFBFB;width:'+this.tabTypeCol[j][1]+'px;" class="cellData"><DIV title="'+this.tabData[i][j]+'" class="DivTexData">'+this.tabData[i][j]+'</DIV></DIV>');
            tabTemp.push('<DIV class="cellSep"></DIV>');                
        }
        //id of the last cell
        idC=this.id+"_CellTab_"+i+"_"+this.NbreCol;
        tabTemp.push('<DIV  ID="'+idC+'" class="cellData" style="background:#FBFBFB;width:'+this.widthLastCell+'px;"></DIV>');
        tabTemp.push('<DIV type="cell" class="cellDec">');        
        tabTemp.push('<IMG class="imgCell" src="'+rialtoConfig.pathRialtoE + 'images/imgTableau/bordblanc_d.gif"></IMG>');
        tabTemp.push('</DIV>');
    }        
    else{    
        //cell without background color and image
        tabTemp.push('</DIV>');
        for(var j=0;j<this.NbreCol;j++)
        {
            //cell id
            idC=this.id+"_CellTab_"+i+"_"+j;
            tabTemp.push('<DIV ID="'+idC+'"  style="width:'+this.tabTypeCol[j][1]+'px;" class="cellData"><DIV title="'+this.tabData[i][j]+'" class="DivTexData">'+this.tabData[i][j]+'</DIV></DIV>');
            tabTemp.push('<DIV class="cellSep"></DIV>');                
        }
        //id of the last cell
        idC=this.id+"_CellTab_"+i+"_"+this.NbreCol;
        tabTemp.push('<DIV  ID="'+idC+'" class="cellData" style="width:'+this.widthLastCell+'px;"></DIV>');
        tabTemp.push('<DIV type="cell" class="cellDec"></DIV>');                        
    }
    tabTemp.push('</DIV>');                   
    return tabTemp.join('');
}


//refresh navigation area
rialto.widget.Grid.prototype.majZoneNavigation=function(){

    // put the buuton only if the rank is > to the line number
    if (this.rang < this.NbreLig){    
        //set text
        var text = (this.debInd+1)+"-"+(this.finInd)+" (total:"+(this.NbreLig)+")";

        //set the button visible if they were hidden
        if(!this.bouFirst.visible){
            this.bouFirst.setVisible(true);
            this.boutPrevious.setVisible(true);
            this.boutNext.setVisible(true);
            this.boutLast.setVisible(true);
        }
        //change alt of the button
        this.bouFirst.setAlt(this.rang+" first");
        this.boutPrevious.setAlt(this.rang+" previous");
        this.boutNext.setAlt(this.rang+" next");
        this.boutLast.setAlt(this.rang+" last");
    }              
    else{
        //set text
        var text = "1-"+this.NbreLig;
        //hide the button if they were visible
        if(this.bouFirst.visible){
            this.bouFirst.setVisible(false);
            this.boutPrevious.setVisible(false);
            this.boutNext.setVisible(false);
            this.boutLast.setVisible(false);
        }
        
    }
    this.setText(text);
}

rialto.widget.Grid.prototype.addText=function(nIndex,texte,objStyle,boolSur){
/*    fonction qui rajout un surtexte ? la ligne dont l'indice est pass? en parametre
        nIndex: indice de la ligne
        texte: texte ? affich?
        objStyle: style de la ligne de texte
        boolSur:si true=surTexte sinon soustexte
*/
    var oThis=this;
    var line=this.tableauHTML.childNodes[nIndex];
    //si il ya deja un sTexte on l'enleve
    /*if (line.sTexte){
        this.removeText(nIndex,true);
    }*/
    
    this.tableauHTML.childNodes[nIndex].style.height=parseInt(this.tableauHTML.childNodes[nIndex].style.height)+19;
    var divTexte=document.createElement("DIV");
    divTexte.appendChild(document.createTextNode(texte));
    //style par d?faut           
    divTexte.style.width=this.width-28;    
    
    if(boolSur){        
        divTexte.className="subTexte";
        this.tableauHTML.childNodes[nIndex].insertBefore(divTexte,this.tableauHTML.childNodes[nIndex].firstChild)
    }
    else{
        divTexte.className="sousTexte";        
        //couleur de fond
        if (nIndex%2==1){ 
            divTexte.style.background="#FBFBFB"; 
        }
        else{
            divTexte.style.background="#F3F3F3"; 
        }
        //on rajout l'image +/- qui afiche ou masque le sous texte A REVOIR........
        this.srcPlus=rialtoConfig.pathRialtoE + "images/imTreeview/icT/plus.gif";
        this.srcMoins=rialtoConfig.pathRialtoE + "images/imTreeview/icT/minus.gif";
        this.tableauHTML.childNodes[nIndex].img=document.createElement("IMG");
        this.tableauHTML.childNodes[nIndex].childNodes[this.tableauHTML.childNodes[nIndex].childNodes.length-1].appendChild(this.tableauHTML.childNodes[nIndex].img)
        this.tableauHTML.childNodes[nIndex].img.src=this.srcMoins;        
        this.tableauHTML.childNodes[nIndex].img.div=divTexte;
        this.tableauHTML.childNodes[nIndex].img.plus=false;
        this.tableauHTML.childNodes[nIndex].img.nIndex=nIndex;
        this.tableauHTML.childNodes[nIndex].img.onclick=function(){
            var nIndex=this.nIndex;
            if (this.plus){
                this.src=oThis.srcMoins;  
                oThis.tableauHTML.childNodes[nIndex].style.height=parseInt(oThis.tableauHTML.childNodes[nIndex].style.height)+19;
                this.div.style.display='block';
                this.plus=false;
            }
            else{
                this.src=oThis.srcPlus;  
                this.div.style.display='none';
                oThis.tableauHTML.childNodes[nIndex].style.height=parseInt(oThis.tableauHTML.childNodes[nIndex].style.height)-19;
                this.plus=true;
            }
            stopEvent();
        }
        
        divTexte.style.position="absolute";
        divTexte.style.top=this.lineHeight;        
        this.tableauHTML.childNodes[nIndex].appendChild(divTexte)
    }
    //applique un style eventuel
    for (prop in objStyle){
        eval("divTexte.style."+prop+"=objStyle."+prop);
        //si c'est le heigth il faut modifier la taille de la ligne
        if (prop=="height"){            
            this.tableauHTML.childNodes[nIndex].style.height=parseInt(this.lineHeight)+parseInt(objStyle.height);
        }
    }
    //on rajoute la valeur au tableau
    //alert("nIndex:"+nIndex+" this.tableauHTML.childNodes[nIndex].ind:"+this.tableauHTML.childNodes[nIndex].ind);
    this.tabData[this.tableauHTML.childNodes[nIndex].ind].sTexte={texte:texte,objStyle:objStyle,boolSur:boolSur}
    //m?morise au niveau de la ligne HTML
    this.tableauHTML.childNodes[nIndex].sTexte=divTexte;
}

rialto.widget.Grid.prototype.removeText=function(indL,boolDansJS){
    //on gere une ligne
    var line=document.getElementById(this.id+"_LineTab_"+indL);
    if(line){    
        line.removeChild(line.sTexte);
        if(line.img){line.removeChild(line.img);}    
        line.sTexte=null;
        line.style.height=this.lineHeight;
    }
    if(boolDansJS){
        this.tabData[indL].sTexte=null;
    }
}

//to change the text of a cell
rialto.widget.Grid.prototype.setCellText=function(indL,indC,text) {   
    //maj dans le tableau js
    this.tabData[indL][indC]=text;
    //si la cellule existe dans le tableau HTML on va la mettre ? jour
    var cell=document.getElementById(this.id+"_CellTab_"+indL+"_"+indC);
    if(cell){
    	var i=0;
    	divText=cell.childNodes[i];
		//on cherche la cellule contenant le texte
		while(divText.className!="DivTexData" && i<cell.childNodes.length){
			i+=1;
			divText=cell.childNodes[i];
		}
		
		divText.innerHTML=text;
    }       
}

//to get the text of a cell
rialto.widget.Grid.prototype.getCellText=function(indL,indC) {
    //maj dans le tableau js
    return this.tabData[indL][indC];    
}

//get index of a line (node represent the HTML line)
rialto.widget.Grid.prototype.getLineIndex=function(node) {
    //split l'id			
	tab=node.id.split("_");	
	if(node.id.indexOf(this.id+"_CellTab_")){
		//pour une cellule
		indL=tab[tab.length-2];
	}
	else{	
		//pour une ligne
		indL=tab[tab.length-1];
	}
	return indL
}

//get index of a cell (node represent the HTML cell)
rialto.widget.Grid.prototype.getCellIndex=function(node) {
    //split l'id			
	tab=node.id.split("_");	
	if(node.id.indexOf(this.id+"_CellTab_")){
		//pour une cellule
		return tab[tab.length-1];
	}
}
		

//set style attribute of a cell
//if indCell =-1 apply to each cell of the line
//if no obStyle parameter then we apply the style save for the cell 
rialto.widget.Grid.prototype.setStyle=function(indL,indC,obStyle) {                     
    if (indC!=-1){        
        //if obStyle add each old style value that are not in this one
        if(obStyle){
            if (this.tabData[indL].cellProp[indC].obStyle!=null){
                oldObStyle=this.tabData[indL].cellProp[indC].obStyle;
                for (prop in oldObStyle){
                    if (obStyle[prop]==null){                        
                        obStyle[prop]=oldObStyle[prop];
                    }
                }
            }                       
            this.tabData[indL].cellProp[indC].obStyle=obStyle;
        }
        else{
			//get the style already save for this cell
            var obStyle=this.tabData[indL].cellProp[indC].obStyle;
        }
                
        //if the cell exist in the HTML array we update the style attribute
        var cell=document.getElementById(this.id+"_CellTab_"+indL+"_"+indC);
        if(cell){                    
            for (prop in obStyle){
                try {                    
                    cell.style[prop]=obStyle[prop];
                }
                catch (erreur) {}
            }
        }
    }
    else{
        //set style to each cell of the line
        for(var j=0;j<(this.NbreCol+1);j++){this.setStyle(indL,j,obStyle);}        
    }               
                                        
}

//disable cell (remove click,dbleclick,mouse event)
//if indCell =-1 apply to each cell of the line
rialto.widget.Grid.prototype.disableLine=function(indL,indC) {                   
        if (indC!=-1){                                                
            //if the cell exist in the HTML array we update
            var cell=document.getElementById(this.id+"_CellTab_"+indL+"_"+indC);
            if(cell){                            
                cell.onclick= function (){};
                cell.ondblclick= function (){};
                cell.onmouseover= function (){stopEvent();};
                cell.onmouseout= function (){stopEvent();};                                
            }
        }
        else{                
            //if the line exist in the HTML array we update
            var line=document.getElementById(this.id+"_LineTab_"+indL);
            if (line){                                
                //pour le clic on inactive toutes les cellules de la ligne
                for(var j=0;j<this.NbreCol;j++){
                    var cell=document.getElementById(this.id+"_CellTab_"+indL+"_"+j);            
                    cell.onclick= function (){};
                    cell.ondblclick= function (){};                
                }                                       
                line.onmouseover= function (){};
                line.onmouseout= function (){};                                
            }
        }                                                       
}


rialto.widget.Grid.prototype.addObjectInCell=function(indL,indC,objPar) {
    //add a object in a cell (could be a rialto object)
    //update in javascript array
    this.tabData[indL].cellProp[indC].objPar=objPar;
    //if the cell exist in the HTML array we update
    var cell=document.getElementById(this.id+"_CellTab_"+indL+"_"+indC);
    if(cell){                                    
        if (objPar.placeIn){            
            objPar.placeIn(cell)
        }
        else{
            cell.appendChild(objPar);
        }
    }       
}
rialto.widget.Grid.prototype.removeObjectFromCell=function(indL,indC,objPar) {
    //remove a object in a cell (could be a rialto object)
    //update in javascript array
    this.tabData[indL].cellProp[indC].objPar=null;
    //if the cell exist in the HTML array we update
    var cell=document.getElementById(this.id+"_CellTab_"+indL+"_"+indC);
    if(cell){ 
       cell.removeChild(objPar);      
    }
}

rialto.widget.Grid.prototype.release=function(){
       	   
    //TO SEE AGAIN WITH NEW D&D
    var titleLine = this.tableauEntete.childNodes[0];
    for (var colIdx=0;colIdx<titleLine.childNodes.length;colIdx++){
        var titleItem = titleLine.childNodes[colIdx];
        titleItem.onclick=null;
        titleItem.oCiu=null;
        if (titleItem.dd){
            titleItem.dd=null;
            titleItem.synchroDDMup=null;
            DragAndDrop.release(titleItem);
        }
        titleItem=null;//DragAndDrop
    }

    this.deleteLines();

	if(this.Div_nav){
	    this.arrG.remove();
	    this.arrG.onclick=null;
	    this.arrD.remove();
	    this.arrD.onclick=null;
	    this.bouFirst.remove();
	    this.bouFirst.onclick=null;
	    this.boutPrevious.remove();
	    this.boutPrevious.onclick=null;
	    this.boutNext.remove();
	    this.boutNext.onclick=null;
	    this.boutLast.remove();	 
	    this.boutLast.onclick=null;
	}
	
    if (this.imgBascule){
	    this.imgBascule.onclick=null;
        this.imgBascule.remove();
        this.imgBascule=null;
    }

    this.menuContex.remove();
    this.menuContex.itemClickApplicatif=null;
    this.menuContex=null;
    this.divExt.oncontextmenu=null;
}
// ***********************************************************
// OTHER FUNCTIONS  OF THE GRID (NAVIGATION,SORT,EVENT....)
// ***********************************************************


//To display the next N line
rialto.widget.Grid.prototype.nextN=function(){      
    if (this.debInd+this.rang <this.NbreLig){
        this.debInd+=this.rang;        
        if (this.debInd+this.rang <=this.NbreLig){this.finInd=this.debInd+this.rang}
        else{this.finInd=this.NbreLig}                
        this.refreshGrid();        
    }
}

//To display the previous N line
rialto.widget.Grid.prototype.previousN=function(){   
    if (this.debInd >= this.rang){
        this.finInd=this.debInd;
        this.debInd-=this.rang;        
        this.refreshGrid();        
    }    
}

//To display the first N line
rialto.widget.Grid.prototype.firstN=function(){
    this.debInd=0;
    if(this.NbreLig<this.rang){this.finInd=this.NbreLig}
    else{this.finInd=this.rang}    
    this.refreshGrid();    
}

//To display the last N line
rialto.widget.Grid.prototype.lastN=function(){
    if (this.NbreLig >=this.rang){
        var reste=this.NbreLig%this.rang;
        if (reste!=0){
            //on prend le premier nombre multiple de n jusqu'a la fin du tableau
            this.debInd=this.NbreLig-reste;            
        }
        else{
            //on prend le nbre de ligne - rang
            this.debInd=this.NbreLig-this.rang;
        }
        this.finInd=this.NbreLig;        
        this.refreshGrid();        
    }
}

//sort the javascript array
//ind:index of the column to sort
//boolOrder:ascendant sort(false) or descendant (true) 

rialto.widget.Grid.prototype.triColonne=function(ind,boolOrder){    
       
    //if old column sort
    if (this.oldColCLic!=null){
        //if it is the same we change the sort order
        if (this.oldColCLic.ind==ind && boolOrder==null){
            boolOrder=! this.oldColCLic.boolOrder
        }
        //get old column sort
        var cell=document.getElementById(this.id+"_CellEntete_"+this.oldColCLic.ind);
        //remove the arrow image
        cell.removeChild(this.arrowEnCours);
    }
        
    //get the header cell to sort
    var cell=document.getElementById(this.id+"_CellEntete_"+ind);  
    
    //get the data type
    var type=this.tabTypeCol[ind][0];
    //sort
    this.tabData.sort(compareTwoColumns(ind,boolOrder,type));             
    //add the sort icone
    if (boolOrder){
        this.arrowEnCours= this.arrowUp;
    }
    else{
        this.arrowEnCours= this.arrowDown;
    }
    cell.appendChild(this.arrowEnCours);    
    //save the index,order
    this.oldColCLic={ind:ind,boolOrder:boolOrder};                
}

function compareTwoColumns(nCol, bDescending, sType) {
        var c = nCol;
        if (bDescending){triDesc = 1;}
        else{triDesc = -1;}


        //Number
        if (sType == "number")
        {
            return function (n1, n2) {
                   return (parseInt(n1[c])-parseInt(n2[c]))*triDesc;
            };
        }
        //date (dd/mm/yyyy or d/m/yyyy))
         if (sType == "date")
         {
            return function (n1, n2) {
                    var tab=n1[c].split("/");
                    var date1=new Date(tab[2],tab[1],tab[0]);
                    tab=n2[c].split("/");
                    var date2=new Date(tab[2],tab[1],tab[0]);
                    if (date1>=date2)
                        return -1*triDesc
                    if (date2>date1)
                        return 1*triDesc
                    // a must be equal to b
                        return 0
                 };
        }
        //String
        if (sType == "string")
        {            
            return function (n1, n2) {
                   if (n1[c]>=n2[c])
                        return -1*triDesc
                   if (n1[c]<n2[c])
                        return 1*triDesc
                   // a must be equal to b
                       return 0
            };
        }

}

//EVENT

rialto.widget.Grid.prototype.afterMouseover=function(node){
    //over only if the node is not selected       
    if (!node.sel){                        
        node.style.color="black";                        
        this.onmouseover(node);
    }
}

rialto.widget.Grid.prototype.afterMouseout=function(node){
    //out only if the node is not selected
    if (!node.sel){
        node.style.color="";        
        if (node.type!="line"){
            //it is a cell so we put back her style 
            if (this.tabData[node.indL].cellProp[node.ind].obStyle!=null){
                this.setStyle(node.indL,node.ind);
            }       
        }
        this.onmouseout(node);
    }        
}

rialto.widget.Grid.prototype.oncontextmenu=function(node,e){       
    this.menuContex.srcEvent=node;
    this.menuContex.activeItem(0);                            
    this.menuContex.afficheMenu(e);    
}


//DBLECLICK
//parametres:
//      indLine javascript line  index
//      indCell javascript cell  index

rialto.widget.Grid.prototype.afterOnDbleClick=function(indLine,indCell){             
    //alert("DBLEClick:"+indLine+".."+indCell);
    
    if (this.indLineClic!=indLine ||(this.indLineClic==indLine && this.indCellClic!=indCell)){                                                                                                                        
		//unselect the old selected line
		this.deselNode(this.indLineClic,this.indCellClic);                
		this.selNode(indLine,indCell) 
            
    }
    if(this.writable){
	    var oThis=this;
	    //get HTML node
	    var node=document.getElementById(this.id+"_CellTab_"+indLine+"_"+indCell);    

	 	//tabulation to change cell	 	     
	    node.onkeypress=function(evt){	
	    //===============================			    	
	    	if (!evt) var evt = window.event;
	    	
	    	var keyCode = evt.keyCode ? evt.keyCode :
	                            evt.charCode ? evt.charCode :
	                                            evt.which ? evt.which : void 0;
	    	    
	    //Traitement de la tabulation
		if(keyCode==9 || keyCode==13 || keyCode==27 ||  keyCode==38 || keyCode==40){

			bDecalLine=false;
			bDecalCell=false;
			iDecal=0;
			bReset=false;
			
			switch (keyCode) {
				case 9:
					// tab go to the next cell
		   	      	iDecal=evt.shiftKey ? -1:1;
			        bDecalCell=true;
			        break;
				case 13:
					// Enter 
				    break;
				case 27:
				    // Echap	
				   	bReset=true;
		   	        break;            
				/*case 37:    
					// left
					bDecalCell=true;
					iDecal=-1;
					break;*/
          		case 38:    
					// previous line     
					bDecalLine=true;
					iDecal=-1;
    		        break;            
		        /*case 39:  				   	
		            // right
		            bDecalCell=true;
		            iDecal=1;
    		        break;*/
		        case 40:  				   	
		            // next line
		            bDecalLine=true;
		            iDecal=1
	   		        break;            	           	   		        
			}			
	    	oThis.afterCellEdit(indLine,indCell,oThis.getCellText(indLine,indCell),oThis.text.getValue(),bDecalLine,bDecalCell,iDecal,bReset)
			return false;
    	}
	   }
	      
		//input type		
	    if(this.tabTypeCol[indCell][2]){
	    	//combo
 	        this.text=new rialto.widget.Combo(this.tabTypeCol[indCell][2],"gridCombo",0,0,node.offsetWidth-4,node,{suggest:false});
 	        this.text.selWithText(this.tabData[indLine][indCell]);
	    }
	    else{
	    	//Date
	        if(this.tabTypeCol[indCell][0]=="date"){        
	            var type="D";
	        }
	        else{
	        	//number
	            if(this.tabTypeCol[indCell][0]=="number"){
	                var type="N";        
	            }
	            //text
	            else{	            
	                var type="A";
	            } 
	        }
	        this.text=new rialto.widget.Text("Gridtext",0,0,node.offsetWidth-4,type,node);        	           
	        this.text.setValue(this.tabData[indLine][indCell]);
	    }
	   	//set with cell value	    
	    this.text.setFocus();	    
	}
	//applicative code
    this.ondbleclick(indLine,indCell);
}

//Todo after cell edit
rialto.widget.Grid.prototype.afterCellEdit=function(indLine,indCell,oldVal,newVal,bDecalLine,bDecalCell,iDecal,bReset){
/*				
	//Verification ?l?mntaire au niveau du champs
	this.text.afterOnBlur();
	if(!this.text.blurOk){return ;}
*/		
	//if no Reset get the new value	
	var bResetA=!this.onCellEdit(indLine,indCell,oldVal,newVal);
	if(!bReset && ! bResetA){
		this.setCellText(indLine,indCell,newVal);
		this.onCellWrite(indLine,indCell,newVal);	    
	}
	this.text.remove();
	this.text=null;
	
	//chech the key press to see what is  the next cell in writable state
	var nouvCell=indCell;
	var nouvLine=indLine;
	var bOpenNextCell=false;
	//cell shift (comme back to the first if it was the last...)
	if(bDecalCell){		
		bOpenNextCell=true;
		nouvCell=parseInt(indCell)+iDecal;
		if(nouvCell>=this.NbreCol){
			nouvCell=0;
		}
		else{
			if(nouvCell<0){
				nouvCell=this.NbreCol-1;
			}
		}		
	}
	//line shift (comme back to the first if it was the last)
	if(bDecalLine){		
		bOpenNextCell=true;
		nouvLine=parseInt(indLine)+iDecal;
		if(nouvLine>=this.tableauHTML.childNodes.length){
			nouvLine=0;
		}
		else{
			if(nouvLine<0){
				nouvLine=this.tableauHTML.childNodes.length-1;				
			}
		}		
	}
	
	//write the next cell 
	if(bOpenNextCell){
		this.afterOnDbleClick(nouvLine,nouvCell);
	}
}             


//CLICK
//parametres:
//      indLine javascript line  index
//      indCell javascript cell  index
//      boolAction to do the onclick attach method (true)
rialto.widget.Grid.prototype.afterOnClick=function(indLine,indCell,boolAction){             
    //alert("Click:"+indLine+".."+indCell);
    //get HTML node
    if (this.cellActive){   
        //look for a cell
        var node=document.getElementById(this.id+"_CellTab_"+indLine+"_"+indCell);
    }
    else{
        //look for a line
        var node=document.getElementById(this.id+"_LineTab_"+indLine);
    }
    
    if(this.multiSelect){
        //we can select multi line
        //so if the line was already selected we unselect it
        if (node.sel){                                           
            this.deselNode(indLine,indCell)
            if (boolAction){
				//applicative code
                this.onDeclickApplicatif(indLine,indCell);
            }            
        }
        else{            
            this.selNode(indLine,indCell)
            if (boolAction){
                //applicative code
                this.onclick(indLine,indCell);
            }
        }
    }
    else{                  
        if(this.indLineClic!=-1){         	
	        //unselect the current line or cell selected                                                     
            //if the selection is on the line we check that it is not the same line
            //if the selection is on the cell we check that it is not the same line
            //or if it is the same that it is not the same cell
            if ((!this.cellActive && this.indLineClic!=indLine) ||
                (this.cellActive && (this.indLineClic!=indLine ||(this.indLineClic==indLine && this.indCellClic!=indCell))))
            {                                                                                                                        
                //unselect the element                                                                                                                       
                this.deselNode(this.indLineClic,this.indCellClic);                
                this.selNode(indLine,indCell)                  
                if (boolAction){
                    //applicative code
                    this.onclick(indLine,indCell);
                }
            }                  
        }
        else{            
            this.selNode(indLine,indCell)                  
            if (boolAction){
                ////applicative code
                this.onclick(indLine,indCell);
            }        
        }
    }                    
}

rialto.widget.Grid.prototype.selNode=function(indLine,indCell) {
    //alert("Sel:"+indLine+".."+indCell);
    //get HTML node
    if (this.cellActive){   
        //look for a cell
        var node=document.getElementById(this.id+"_CellTab_"+indLine+"_"+indCell);
    }
    else{
        //look for a line
        var node=document.getElementById(this.id+"_LineTab_"+indLine);
    }    
    node.sel=true;
    
     //cell  where to add the selected icon
    if (node.type=="line"){                       
        var cellCoche=node.childNodes[1]
        this.tabData[indLine].sel=true;
    }              
    else{    
        var cellCoche=node
        this.tabData[indLine].cellProp[indCell].sel=true;
    }
    divCoche=this.divCoche.cloneNode(true);    
    cellCoche.insertBefore(divCoche,cellCoche.firstChild); 
    node.style.border="1px solid #0099CC";     
  	//node.style.width=node.offsetWidth-2;
   	//node.style.height=node.offsetHeight-2;
    //node.style.background="#FBFBFB";
    node.style.color="#0099FF";
    //save the selected index of line and cell
    this.indLineClic=indLine;
    this.indCellClic=indCell;    
}


rialto.widget.Grid.prototype.deselNode=function(indLine,indCell) {    
       
    //alert("Desel:"+indLine+".."+indCell);                
    //get HTML node
    if (this.cellActive){   
        //look for a cell
        var node=document.getElementById(this.id+"_CellTab_"+indLine+"_"+indCell);
    }
    else{
        //look for a line
        var node=document.getElementById(this.id+"_LineTab_"+indLine);
    }    
    if(node){
        //to unselect the node
        node.sel=false;    
        node.style.border="";    
    	//node.style.width=parseInt(ria.utils.measures.$getStyle(node,'width'))+2;
    	//node.style.height=parseInt(ria.utils.measures.$getStyle(node,'height'))+2;
        node.style.fontWeight=''; 
        node.style.color="";
        //node.style.background="";
        
        if (node.type=="line"){            
            //cell that contain the selected icon
            var cellCoche=node.childNodes[1]            
            for(var j=0;j<this.NbreCol;j++){
                //si la cellule ? un style d?finit
                objS=this.tabData[indLine].cellProp[j].obStyle;
                if (objS!=null){this.setStyle(indLine,j);}                
            }
        }              
        else{        
            if (indLine%2!=0){  
                //white background
                node.style.background="#FBFBFB";
            }
            //cell that contain the selected icon
            var cellCoche=node;            
            objS=this.tabData[indLine].cellProp[indCell].obStyle;
            if (objS!=null){this.setStyle(indLine,indCell);}
        }  
        //remove select icon
        if(cellCoche.childNodes.length>0){cellCoche.removeChild(cellCoche.firstChild)};    
    }
    //unselect in javascript properti
    if (!this.cellActive){                
        this.tabData[indLine].sel=false;                
    }              
    else{                        
        this.tabData[indLine].cellProp[indCell].sel=false;                
    }
    this.indLineClic=-1;
    //handling of edit
    if (this.text){
	  	if(this.text.type=="combo"){
        	var val=this.text.getSelText();
    	}
    	else{
	   	   	var val=this.text.getValue();
    	}
       this.afterCellEdit(indLine,indCell,this.getCellText(indLine,indCell),val,false,false,0,false)
    }
}

rialto.widget.Grid.prototype.unselectLine=function() {
    //function to unselect a line in the HTML array
    if(this.indLineClic!=-1){
        this.deselNode(this.indLineClic,this.indCellClic);        
    }
}

rialto.widget.Grid.prototype.clickLine=function(indLine,indCell) {
    //function to simulate line click     
    this.afterOnClick(indLine,indCell,true);
}

rialto.widget.Grid.prototype.clickNext=function() {
    //simulate next line click
    ind=parseInt(this.indLineClic)+1;        
    
    if(this.navigation){    
        //if more than the rank display next line
        if(ind>=this.finInd){            
            this.nextN();           
        }    
    }
    else{
        //if less then the rank display previous line
        if(ind>this.NbreLig-1){
            ind=0;
        }    
    }
    //do the click
    this.afterOnClick(ind,this.indCellClic,true);

}

rialto.widget.Grid.prototype.clickPrevious=function() {
    //simulate previous line click
    ind=parseInt(this.indLineClic)-1;        
    
    if(this.navigation){    
        //if less than the rank display previous line
        if(ind<this.debInd){
            this.previousN();            
        }    
    }
    else{
        //if less then the first line restart from the last
        if(ind<0){
            ind=this.NbreLig-1;
        }    
    }
    //do the click
    this.afterOnClick(ind,this.indCellClic,true);   
}

rialto.widget.Grid.prototype.clickLast=function() {
    //simulate last line click
    if(this.navigation){this.lastN();}
    this.afterOnClick(parseInt(this.NbreLig)-1,this.indCellClic,true)
}

rialto.widget.Grid.prototype.clickFirst=function() {
    //simulate first line click
    if(this.navigation){this.firstN();}    
    this.afterOnClick(0,this.indCellClic,true)
}

//DBLECLICK AND CLICK APPLICATIVE CALL
//parametres:
//      indLine javascript line  index
//      indCell javascript cell  index
rialto.widget.Grid.prototype.ondbleclick=function(indLine,indCell) {
//The code must be redefine after the instanciation of the component. By default this method does nothing.
}

rialto.widget.Grid.prototype.onclick=function(indLine,indCell) {
//The code must be redefine after the instanciation of the component. By default this method does nothing.
}

rialto.widget.Grid.prototype.onCellEdit=function(indLine,indCell,oldVal,newVal) {
//The code must be redefine after the instanciation of the component. By default this method does nothing.
//must return true to validate the seizure or false to reset it
return true
}

rialto.widget.Grid.prototype.onCellWrite=function(indLine,indCell,newVal) {
//The code must be redefine after the instanciation of the component. By default this method does nothing.
//to do after cell change
}

rialto.widget.Grid.prototype.onDeclickApplicatif=function(indLine,indCell) {
//The code must be redefine after the instanciation of the component. By default this method does nothing.
//raise when a line is unselect (only in multi select mode)
}
